//
#import "BKObject.h"
#import "BKType.h"

@implementation BKObject

- (id) initWithName: (NSString*) name signatures: (BKSignatures*) sigs
{
	if(self = [super init])
	{
		self.name = name;
		self.signatures = sigs;
	}
	return self;
}

- (id) initWithXMLElement: (NSXMLElement*) elem signatures: (BKSignatures*) sigs
{
	NSXMLNode* theNode = [elem attributeForName: @"name"];
	return [self initWithName: [theNode stringValue] signatures: sigs];
}

@synthesize name = _name;
@synthesize signatures = _sigs;

- (NSString*) description
{
	return [NSString stringWithFormat: @"<%@: %p, name=%@>",
		NSStringFromClass([self class]), self, _name];
}

@end


@implementation BKTypedObject

- (id) initWithXMLElement: (NSXMLElement*) elem signatures: (BKSignatures*) sigs
{
	if(self = [super initWithXMLElement: elem signatures: sigs])
	{
		NSXMLNode* theNode = nil;
#if __LP64__
		theNode = [elem attributeForName: @"type64"];
#endif
		if(theNode == nil)
			theNode = [elem attributeForName: @"type"];
			
		self.typeString = [theNode stringValue];
	}
	return self;
}

- (void) dealloc
{
	[_typeString release];
	[_type release];
	[super dealloc];
}

@synthesize typeString = _typeString;

- (BKType*) type
{
	if(_type == nil)
		_type = [[BKType typeWithString: _typeString] retain];
	return _type;
}

- (NSString*) description
{
	return [NSString stringWithFormat: @"<%@: %p, name=%@, type=%@>",
		NSStringFromClass([self class]), self, _name, self.type];
}

@end
